<?php
namespace Home\Model;
use Think\Model;
// +----------------------------------------------------------------------
// | Date:2017年9月11日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class CheckinoutModel extends Model{
    
    function getlist_xry(){
        $A = $this->where(['id'=>'72539'])->find();
        dump($A);
    }
    
    
     
    /**
     * 获取编辑打卡数据
     * @param unknown $lastid
     * @param unknown $limit
     * @param string $prefix
     * @return unknown
     * date:2017年9月11日
     * author: EK_熊
     */
    
    function getlist($lastid,$limit,$prefix=''){
        
        if (is_array($lastid)){
            $map['ckin.id'] = ['in',$lastid];
        }else{
            
            $map = [
                'ckin.id'=>['gt',$lastid],
            ];
        }
        $prefix = $prefix.'_';
        $field = [
            "ckin.id"=>'dev_id',
            "CONVERT(varchar(100),checktime,120)"=>'time',
            'name',
            "CASE WHEN LEN(badgenumber)<4 THEN right('0000'+badgenumber,4) ELSE badgenumber END"=>'sn',
            "('$prefix'+mac.machinealias)"=>'dev_code',
        ];
        
        
        $join = [
            'LEFT JOIN __USERINFO__ uifo ON ckin.userid = uifo.userid',
            'LEFT JOIN __MACHINES__ mac ON ckin.sn = mac.sn'
        ];
        
        $ret = $this->alias('ckin')->where($map)->field($field)->join($join)->limit($limit)->order('dev_id')->select();
        
        return $ret; 
    }
    
    /**
     * 获取时间日期，当天的全部打卡数据id
     * @param unknown $day
     * date:2017年11月6日
     * author: EK_熊
     */
    function check_ids($day){
        //获取某一天的全部数据id
        $map['_string']="checktime >= '$day 00:00:00' AND checktime <= '$day 23:59:59'";
        $ids = $this->where($map)->getField('id',true);
        return $ids;
    }
    
}